import cv2
import numpy as np

from matplotlib import pyplot as plt

img = cv2.imread('../images/dog2.jpg')
img2 = cv2.resize(img, (300, 500))
# 添加高斯噪声
sigma = 1  # 标准差
gaussian_noise = np.random.normal(0, sigma, img2.shape)
img_noisy = cv2.addWeighted(img2, 0.9, gaussian_noise.astype(np.uint8), 0.2, 0)
# 高斯滤波
gauss = cv2.GaussianBlur(img_noisy, (5, 5), 1)
# 均值滤波
dst = cv2.blur(img_noisy, (5, 5))
# 中值滤波
median = cv2.medianBlur(img_noisy, 5)
res1 = np.hstack((img2, gauss))
res2 = np.hstack((dst, median))
res3 = np.vstack((res1, res2))
cv2.imshow('res', res3)
cv2.waitKey(0)
cv2.destroyAllWindows()